<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>replace（）方法使用字符串</title>
</head>
<body>
<p>替换“Microsoft”为“Runoob”：</p>
<button onclick="myFunction()">点我</button>
<p id="demo">请问我Microsoft！</p>
<script>
    function myFunction() {
        var str = document.getElementById("demo").innerHTML;
        var txt = str.replace("Microsoft","Runoob");
        document.getElementById("demo").innerHTML = txt;
    }
</script>
</body>
</html>